<!--link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl.WWWROOT_BACKEND; ?>/css/form.css"/-->

<div class="wd-form">

	<?php /** @var BootActiveForm $form */
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'id' => 'article-form',
	//'enableAjaxValidation' => true,
  'htmlOptions'=>array('enctype'=>'multipart/form-data','class'=>'well'),
    
    
)); ?>
	<fieldset>

	<p class="note">
		<?php echo Yii::t('app', 'Fields with'); ?> <span class="required">*</span> <?php echo Yii::t('app', 'are required'); ?>.
	</p>
	
		<div class="wd-input">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model, 'title', array('maxlength' => 128)); ?>
		<?php echo $form->error($model,'title'); ?>
        <script type="text/javascript" language="javascript">
            jQuery(document).ready(function() {
                $('#Article_title').keyup(function(){
                    createAlias();
                });
                $('#Article_title').focusout(function(){
                    createAlias();
                });
								
				function createAlias()
				{
					var value = $('#Article_title').val();
					value = value.replace(/[áàảãạăắằẳẵặâấầẩẫậ]/ig, 'a');
					value = value.replace(/[đ]/ig, 'd');
					value = value.replace(/[éèẻẽẹêếềểễệ]/ig, 'e');
					value = value.replace(/[íìỉĩị]/ig, 'i');
					value = value.replace(/[óòỏõọôốồổỗộơớờởỡợ]/ig, 'o');
					value = value.replace(/[úùủũụưứừửữự]/ig, 'u');
					value = value.replace(/[ýỳỷỹỵ]/ig, 'y');
					value = value.replace(/[^A-Za-z0-9\s_-]/ig, '');
					value = value.replace(/\s/ig, '-');
					value = value.toLowerCase();
					$('#Article_alias').val(value);
				}
            });
        </script>
		</div><!-- wd-input -->
		<?php echo $form->hiddenField($model, 'alias', array('maxlength' => 128)); ?>
		
		<div class="wd-input">
		<?php echo $form->labelEx($model,'category_id'); ?>
		<?php
			$criteria = new CDbCriteria;
			$criteria->compare('is_published', 1, true);
			//$criteria->addCondition('is_published', 1, true);
			//$criteria->compare('user_id', Yii::app()->user->id, true);
			$criteria->compare('user_categories.user_id', Yii::app()->user->id, true);
			//$criteria->addCondition('user_categories.user_id', Yii::app()->user->id, true, 'OR');
			$criteria->with = array('user_categories');
			$criteria->order = 'name ASC';
			
			$datas=Category::model()->findAll($criteria);
			$dropDownDatas = CHtml::listData($datas , 'id', 'name');
			echo $form->dropDownList($model,'category_id', $dropDownDatas, array('empty'=>'Select category')
					//$model()->findAll(), 'id', 'name', 'parrent_id'),
			); 
		?>
		<?php echo $form->error($model,'category_id'); ?>
		</div><!-- wd-input -->
		<div class="wd-input">
		<?php echo $form->labelEx($model,'sub_category_id'); ?>
		<?php
			$subDatas=SubCategory::model()->findAll(array("condition"=>"is_published == 1", 'order'=>'name ASC'));
			$dropDownDatas = CHtml::listData($subDatas , 'id', 'name');
			echo $form->dropDownList($model,'sub_category_id', $dropDownDatas, array('empty'=>'Select sub category')
					//$model()->findAll(), 'id', 'name', 'parrent_id'),
			); 
		?>
		<?php echo $form->error($model,'sub_category_id'); ?>
		</div><!-- wd-input -->
		<?php if(Yii::app()->controller->module->image['show']) { ?>
		<div class="wd-input">
			<?php echo $form->labelEx($model,'image'); ?>
			<div class="image-form">
			<?php if (isset($model->image) && ($model->image != 'NULL')): ?>
				<?php if(file_exists(Yii::app()->createUrl('/').'wwwroot/upload_files/articles/' . $model->image)): ?>
					<img src="<?php echo  Yii::app()->createUrl('/').'/wwwroot/upload_files/articles/' . $model->image; ?>" width="100" height="70"/>
				<?php else : ?>
					<?php echo CHtml::image('/wwwroot/upload_files/articles/no-image.png', 'Image', array(
								'width'		=>	'100',
								'height'	=>	'70'
					)); ?>
				<?php endif ?>
				<div class="clr"></div>
			<?php endif ?>
			<?php echo $form->fileField($model,'image'); ?>
			</div>
		<?php echo $form->error($model,'image'); ?>
		</div><!-- wd-input -->
		<?php } ?>
		
		<?php if(Yii::app()->controller->module->description['show']) { ?>
		<div class="wd-input">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model, 'description'); ?>
		<?php echo $form->error($model,'description'); ?>
		</div><!-- wd-input -->
		<?php } ?>
		
		<div class="wd-input">
		<?php echo $form->labelEx($model,'content'); ?>
		<?php //echo $form->textArea($model, 'content'); ?>
		<div class="ckeditor">
		<?php $this->widget('application.extensions.ckeditor.CKEditor', array(
			'model'=>$model,
			'attribute'=>'content',
			'language'=>'en',
			'editorTemplate'=>'advanced',
			'width'	=>	'620px',
			'height'	=>	'620px',
			'options'=>array(
				'filebrowserUploadUrl'=>$this->createUrl('upload'),
			),
			//'rows'=>10, 
			//'cols'=>30,
			'toolbar'=>array(
				array('Bold', 'Italic', 'Underline', 'Strike'),
				array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'),
				array('Format'),
				array( 'Font', 'FontSize', 'FontColor', 'TextColor'),
				'/',
				array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord' ),
				array('Image', 'Table', 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'),
				array('Subscript','Superscript'),
				array( 'Link', 'Unlink' ),
				array('Source'),
			)
			)); 
		?>
		</div>
		<?php echo $form->error($model,'content'); ?>
		</div><!-- wd-input -->
		
		<div class="wd-input">
		<?php echo $form->labelEx($model,'source'); ?>
		<?php echo $form->textField($model, 'source', array('maxlength' => 128)); ?>
		<?php echo $form->error($model,'source'); ?>
		</div>

		<?php echo $form->checkboxRow($model, 'is_published'); ?>
		
		<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'Save')); ?>
	</fieldset>

<?php
$this->endWidget();
?>
</div><!-- form -->